package Controlor;


import Model.DAO.uselessDao.BookDao;
import Model.useless.BookForm;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/searchbook")
public class CheckSearch extends HttpServlet{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String keyworld = req.getParameter("keyworld");
        List<BookForm> bookForms = new BookDao().searchBook(keyworld);
        if(bookForms.size()!=0){
            HttpSession session=req.getSession();
            session.setAttribute("searchresult",bookForms);
            //转到系统主界面
            req.getRequestDispatcher("display.jsp").forward(req, resp);
        }
        else {
            req.setAttribute("insertinfo",3);
            req.getRequestDispatcher("Tip.jsp").forward(req, resp);//转到错误页
        }
    }
}
